

function addArduinoCod(Blockly) {






    Blockly.Arduino['EXT_RGB_LIGHT_RING_BLOCK_1607494529660'] = function (block) {
        let pin = this.getFieldValue('pin');

        Blockly.Arduino.definitions_['include_EXT_RGB_LIGHT_RING_BLOCK_1607494529660'] = `\n#include "RGBLed.h"\n#define RgbPin ${pin}`;
        Blockly.Arduino.definitions_['define_EXT_RGB_LIGHT_RING_BLOCK_1607494529660'] = ``;
        Blockly.Arduino.definitions_['setup_EXT_RGB_LIGHT_RING_BLOCK_1607494529660'] = ``;
        return `\r\n`;
    }



    Blockly.Arduino['EXT_RGB_LIGHT_RING_BLOCK_1607494529773'] = function (block) {
        let brightness = Blockly.Arduino.valueToCode(this, 'brightness', Blockly.Arduino.ORDER_ATOMIC);

        Blockly.Arduino.definitions_['include_EXT_RGB_LIGHT_RING_BLOCK_1607494529773'] = ``;
        Blockly.Arduino.definitions_['define_EXT_RGB_LIGHT_RING_BLOCK_1607494529773'] = ``;
        Blockly.Arduino.definitions_['setup_EXT_RGB_LIGHT_RING_BLOCK_1607494529773'] = ``;
        return `mRgb.setBrightness(${brightness});\r\n`;
    }



    // Blockly.Arduino['EXT_RGB_LIGHT_RING_BLOCK_1607494529947'] = function (block) {
    //     let ln = Blockly.Arduino.valueToCode(this, 'ln', Blockly.Arduino.ORDER_ATOMIC);
    //     let lb = Blockly.Arduino.valueToCode(this, 'lb', Blockly.Arduino.ORDER_ATOMIC);
    //     let le = Blockly.Arduino.valueToCode(this, 'le', Blockly.Arduino.ORDER_ATOMIC);
    //     let duration = Blockly.Arduino.valueToCode(this, 'duration', Blockly.Arduino.ORDER_ATOMIC);
    //     let R = Blockly.Arduino.valueToCode(this, 'R', Blockly.Arduino.ORDER_ATOMIC);
    //     let G = Blockly.Arduino.valueToCode(this, 'G', Blockly.Arduino.ORDER_ATOMIC);
    //     let B = Blockly.Arduino.valueToCode(this, 'B', Blockly.Arduino.ORDER_ATOMIC);

    //     Blockly.Arduino.definitions_['include_EXT_RGB_LIGHT_RING_BLOCK_1607494529947'] = `\n#include "RGBLed.h"`;
    //     Blockly.Arduino.definitions_['define_EXT_RGB_LIGHT_RING_BLOCK_1607494529947'] = `RGBLed mRgb(RgbPin,${ln});\r\nint delayval = ${duration};`;
    //     Blockly.Arduino.definitions_['setup_EXT_RGB_LIGHT_RING_BLOCK_1607494529947'] = ``;
    //     return `for(int i= ${lb}-1;i< ${le};i++){\r\n    mRgb.setColorAt(i, ${R}, ${G}, ${B});\r\n    mRgb.show();\r\n    delay(delayval);\r\n  }\r\n`;
    // }


    Blockly.Arduino['EXT_RGB_LIGHT_RING_BLOCK_1607494529947'] = function(block) {
        var value_total = Blockly.Arduino.valueToCode(this, 'ln', Blockly.Arduino.ORDER_ATOMIC);
        var value_start = Blockly.Arduino.valueToCode(this, 'lb', Blockly.Arduino.ORDER_ATOMIC);
        var value_end = Blockly.Arduino.valueToCode(this, 'le', Blockly.Arduino.ORDER_ATOMIC);
        var value_red = 0;
        var value_green = 0;
        var value_blue = 0;
        var value_lightTime = Blockly.Arduino.valueToCode(this, 'duration', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_mrgb'] = 'RGBLed mRgb(RgbPin,'+ value_total+');\n';
        Blockly.Arduino.definitions_['include_ph_time'] = 'int delayval = '+ value_lightTime +';';
        var dropdown_rgbColor = block.childBlocks_[4].colour_; 
        var colorStr = dropdown_rgbColor.colorRgb();
        if (colorStr) {
          var colorArr = colorStr.split(",");
          value_red = colorArr[0];
          value_green = colorArr[1];
          value_blue = colorArr[2];
       }
        // Blockly.Arduino.definitions_['include_ph_pixels'] = 'Adafruit_NeoPixel pixels = Adafruit_NeoPixel('+value_total+', rgbRing.pin1(), NEO_GRB + NEO_KHZ800);';
        var code = 'for(int i='+value_start +'-1;i<'+ value_end +';i++){\n    mRgb.setColorAt(i, ' + value_red + ', ' + value_green + ', ' + value_blue + '); \n    mRgb.show(); \n'+
          '    delay(delayval);\n}';
        return code;
      }

    return Blockly;
}

module.exports = addArduinoCod;

